"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Base64ToFile = exports.FileToBase64 = exports.Base64ToBlob = exports.BlobToBase64 = exports.FileToBlob = exports.BlobToFile = void 0;
function ReadBase64(file, callback) {
    const reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = () => {
        callback(reader.result);
    };
}
function BlobToFile(blob, name, options) {
    return new File([blob], name, options);
}
exports.BlobToFile = BlobToFile;
function FileToBlob(file, options) {
    return new Blob([file], options);
}
exports.FileToBlob = FileToBlob;
function BlobToBase64(blob) {
    return new Promise(resolve => {
        ReadBase64(blob, (base64) => {
            resolve(base64);
        });
    });
}
exports.BlobToBase64 = BlobToBase64;
function Base64ToBlob(base64) {
    const arr = base64.split(";base64,");
    let str = "";
    let mime = "";
    if (arr.length === 1)
        str = arr[0];
    else {
        mime = arr[0].split(":")[1];
        str = arr[1];
    }
    const raw = window.atob(str);
    const rawLength = raw.length;
    const uint8Array = new Uint8Array(rawLength);
    for (let i = 0; i < rawLength; i++) {
        uint8Array[i] = raw.charCodeAt(i);
    }
    return new Blob([uint8Array], { type: mime });
}
exports.Base64ToBlob = Base64ToBlob;
function FileToBase64(file) {
    return new Promise(resolve => {
        ReadBase64(file, (base64) => {
            resolve(base64);
        });
    });
}
exports.FileToBase64 = FileToBase64;
function Base64ToFile(base64, name) {
    const blob = Base64ToBlob(base64);
    return BlobToFile(blob, name);
}
exports.Base64ToFile = Base64ToFile;
